import { queryProMatDet, editProgramMat } from '../services/api';

export default {
  namespace: 'promatdet',

  state: {
    matDet: {},
  },

  effects: {
    *fetchProMatDet({ payload, callback }, { call, put }) {
      const response = yield call(queryProMatDet, payload);
      yield put({
        type: 'saveMatDet',
        payload: response.progMatDet,
      });
      if (callback) callback();
    },
    *editProgramMat({ payload, callback }, { call, put }) {
      const { jsonCont } = payload;
      const response = yield call(editProgramMat, { jsonCont: JSON.stringify(jsonCont) });
      //console.log('add mat respone', response);
      if (response?.result?.code === 2001) {
        message.error('提交出错，请检查');
      } else if (callback) callback();
    },
  },

  reducers: {
    saveMatDet(state, action) {
      return {
        ...state,
        matDet: action.payload,
      };
    },
  },
};
